#!/bin/bash

# Compile the client-side app for different browsers.  The host page includes
# a small selection script to pick the correct version to load.

echo "Building deps..."
./build_deps

GOOG_PATH='/devel/clib/goog'
TH_PARTY_PATH='/devel/clib/third_party/closure/goog'

echo "Precompiling..."
python /devel/clbin/closurebuilder.py -i $GOOG_PATH/base.js  -i $GOOG_PATH/deps.js -i $TH_PARTY_PATH/deps.js -i dkpoints/main.js --root=./dkpoints --root=$GOOG_PATH --root=$TH_PARTY_PATH -o script --output_file=precompile.js

echo "Compiling permutations:"

echo "  Webkit"
java -jar /devel/clbin/compiler.jar --define goog.userAgent.jscript.ASSUME_NO_JSCRIPT=true --define goog.dom.ASSUME_STANDARDS_MODE=true --define goog.userAgent.ASSUME_WEBKIT=true --js $GOOG_PATH/deps.js --js precompile.js --compilation_level=ADVANCED_OPTIMIZATIONS --js_output_file=../WAR/root/scripts/dkpoints-webkit.js --jscomp_off=fileoverviewTags --jscomp_error=deprecated --jscomp_error=checkTypes --jscomp_error=checkVars --jscomp_error=invalidCasts --jscomp_error=missingProperties --jscomp_error=undefinedVars --jscomp_error=unknownDefines --warning_level=VERBOSE --output_wrapper "(function(){%output%})()"

echo "  Firefox"
java -jar /devel/clbin/compiler.jar --create_source_map ../WAR/root/scripts/dkpoints-map --define goog.userAgent.jscript.ASSUME_NO_JSCRIPT=true --define goog.dom.ASSUME_STANDARDS_MODE=true --define goog.userAgent.ASSUME_GECKO=true --js $GOOG_PATH/deps.js --js precompile.js --compilation_level=ADVANCED_OPTIMIZATIONS --js_output_file=../WAR/root/scripts/dkpoints-gecko.js --jscomp_off=fileoverviewTags --output_wrapper "(function(){%output%})()"

echo "  Opera"
java -jar /devel/clbin/compiler.jar --define goog.dom.ASSUME_STANDARDS_MODE=true --define goog.userAgent.jscript.ASSUME_NO_JSCRIPT=true --define goog.userAgent.ASSUME_OPERA=true --js $GOOG_PATH/deps.js --js precompile.js --compilation_level=ADVANCED_OPTIMIZATIONS --js_output_file=../WAR/root/scripts/dkpoints-opera.js --jscomp_off=fileoverviewTags --output_wrapper "(function(){%output%})()"

echo "  Internet Explorer"
java -jar /devel/clbin/compiler.jar --define goog.dom.ASSUME_STANDARDS_MODE=true --define goog.userAgent.ASSUME_IE=true --js $GOOG_PATH/deps.js --js precompile.js --compilation_level=ADVANCED_OPTIMIZATIONS --js_output_file=../WAR/root/scripts/dkpoints-ie.js --jscomp_off=fileoverviewTags --output_wrapper "(function(){%output%})()"

echo "  Default"
java -jar /devel/clbin/compiler.jar --define goog.dom.ASSUME_STANDARDS_MODE=true --js $GOOG_PATH/deps.js --js precompile.js --compilation_level=ADVANCED_OPTIMIZATIONS --js_output_file=../WAR/root/scripts/dkpoints.js --jscomp_off=fileoverviewTags --output_wrapper "(function(){%output%})()"

echo "Compilation complete."